__author__ = 'tarek'
#script to upload financials based on Altman ZScore variables. Make sure that the year and quarter fields are up to date

from twitterSentiment.models import Company, CompanyFinancials
import pandas as pd
import ast

def run():
	allcompanyfinancescsv = 'data/altman_results4.csv'
	allcompanyfinances = pd.read_csv(allcompanyfinancescsv)

	for idx,row in allcompanyfinances.iterrows():
		company = Company.objects.get(symbol=row["Symbol"])
		altman = ast.literal_eval(row["altman_variables"])
		companyFinancials = CompanyFinancials(company_id=company.id,
											  total_assets=altman[0],
											  total_liability=altman[1],
											  current_assets=altman[2],
											  current_liability=altman[3],
											  retained_earnings = altman[4],
											  market_capital=altman[5],
											  ebitda = altman[6],
											  sales = altman[7],
											  stockprice=altman[8],
											  date_extracted=row['dateextracted'],
											  year="2014",
											  quarter="3",)
		companyFinancials.save()
		print (idx)
